from tkinter import*
from tkinter.messagebox import*
from tkinter.ttk import*
ke={}

xia={}

wan={}
def write():
    with open('课程表/morning.txt',encoding='UTF-8') as file:
        for line in file:
            line.rstrip('\n')
            zhou,xue=line.split(':')
            ke[zhou]=xue
    with open('课程表\/afternoon.txt',encoding='UTF-8') as file:
        for line in file:
            line.rstrip('\n')
            zhou2,xue2=line.split(':')
            xia[zhou2]=xue2
    with open('课程表\/night.txt',encoding='UTF-8') as file:
        for line in file:
            line.rstrip('\n')
            zhou3, xue3 = line.split(':')
            wan[zhou3] = xue3


def search():
    try:
        if cb.get()=='上午':
            if cbb.get() in ke:
                showinfo('提示','{}{}的课程表是；{}'.format(cbb.get(),cb.get(),ke[cbb.get()]))
            else:
                showinfo('提示','这一天上午无课程！')
        if cb.get() == '下午':
            if cbb.get() in xia:
                        showinfo('提示', '{}{}的课程表是；{}'. format(cbb.get(), cb.get(), xia[cbb.get()]))
            else:
                        showinfo('提示', '这一天下午无课程！')

        if cb.get()=='晚上':
            if cbb.get() in wan:
                showinfo('提示','{}{}的课程表是；{}'.format(cbb.get(),cb.get(),wan[cbb.get()]))
            else:
                showinfo('提示','这一天晚上无课程！')
    except KeyError:
            showwarning('提示','该时段无课程！')



write();
root=Tk()
root.title('课表查询')
root.geometry('330x50+300+300')
var=StringVar(root)
var.set('请选择时间')
cb=Combobox(root,textvariable=var)
cb['value']=('上午','下午','晚上')
cb.grid(row=0,column=0)
var1=StringVar(root)
var1.set('请选择周几')
cbb=Combobox(root,textvariable=var1)
cbb['value']=('周一','周二','周三','周四','周五')
cbb.grid(row=0,column=1)
Button(root,text='确定',command=search).grid(row=1,column=0,columnspan=2)

root.mainloop()
